﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using CardLogistics.Web.Components;
using System.Data;

namespace CardLogistics.Web.MainPage.Basic.BasicType
{
    public partial class ListInfo : BasePage
    {
        private static readonly CardLogistics.DAL.Basic.Basic_BasicTypeData DAL = new DAL.Basic.Basic_BasicTypeData();
        protected void Page_Load(object sender, EventArgs e)
        {
            WebUserControl_ToolBar1.DeleteEvent += new EventHandler(DeleteUC);

            if (!IsPostBack)
            {
                BindRpt();
            }
        }

        #region 绑定数据
        /// <summary>
        /// 绑定数据
        /// </summary>
        /// <param name="pageIndex">当前页页码</param>
        private void BindRpt()
        {
            int recordCount = 0;
            int pageCount = 0;
            string typeNO = "0";//默认为 卡芯片类型 信息 芯片类型的菜单id=24 采购类型菜单id=25
            if (Mid == "100205")
                typeNO = "1";//采购类型 信息
            else if (Mid == "100206")
                typeNO = "2";
            DataTable dt = CardLogistics.DAL.CommonData.QuickPage_Oracle("BASIC_BASICTYPE", "ID", " LASTUPDATEDATE ", WebPageSize, WebPageIndex, " ISDELETE=0 and typeNO=" + typeNO + " ", "*", out pageCount, out recordCount);
            SetNetPagerHtml(AspNetPager1, dt, rptList, recordCount);
        }
        #endregion

        private void DeleteUC(object sender, EventArgs e)
        {
            string typeNO = "";//默认为 卡芯片类型 信息 芯片类型的菜单id=24 采购类型菜单id=25
            if (Mid == "100204")
                typeNO = "卡芯片类型";
            else if (Mid == "100205")
                typeNO = "采购类型";//采购类型 信息
            else if (Mid == "100206")
                typeNO = "入库类型";//入库类型 信息
            string delId = hdf_Id.Value;
            if (!string.IsNullOrEmpty(delId))
            {
                string[] ids = delId.TrimEnd(',').Split(',');
                int resCount = 0;
                for (int i = 0; i < ids.Length; i++)
                {
                    string resStr = DAL.Delete(ids[i]);
                    if (resStr.Split(',')[0] == "ok")
                        resCount++;
                    else if (resStr.Split(',')[0] == "no")
                        ShowMessageBox("系统参数，不允许删除！");
                    else
                        ShowMessageBox("删除失败！");
                }
                BindRpt();
            }
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            WebPageIndex = AspNetPager1.CurrentPageIndex;
            BindRpt();
        }
    }
}